package com.gmall.rabbitmq.producer.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/defalutEx")
public class DefaultExController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    private int i = 0;
    @GetMapping("/produce")
    public String produceSimpleMessage(){
        /**
         * String exchange 交换机  缺省交换机""
         * 缺省交换机 绑定到任何一个队列，routing key就是队列名称
         * 必须绑定，不能删除
         * String routingKey 路由键
         * Object object 消息内容
         */
        rabbitTemplate.convertAndSend(
                "",
                "default_queue1",
                "hello,world " + (i++));
        return "OK";
    }
}
